
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Getting Started &#8212; pyungo v0.7.0 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Features" href="features.html" />
    <link rel="prev" title="Installation" href="install.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<p class="logo">
  <a href="../index.html">
    <img class="logo" src="../_static/pyungo.jpg" alt="Logo"/>
    
  </a>
</p>






<p>
<iframe src="https://ghbtns.com/github-btn.html?user=cedricleroy&repo=pyungo&type=star&count=true&size=large&v=2"
  allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
</p>





<h3>Navigation</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Getting Started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#simple-example">Simple example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="features.html">Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer.html">Developer Documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatsnew.html">What’s New</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
      <li>Previous: <a href="install.html" title="previous chapter">Installation</a></li>
      <li>Next: <a href="features.html" title="next chapter">Features</a></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="getting-started">
<h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
<p><strong>pyungo</strong> is a lightweight library to link a set of dependent functions together,
and execute them in an ordered manner.</p>
<p><strong>pyungo</strong> is built around <strong>Graphs</strong> and <strong>Nodes</strong> used in a
<a class="reference external" href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG</a> (Directed Acyclic Graph).
A <a class="reference internal" href="developer.html#pyungo.core.Node" title="pyungo.core.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></a> represent a function being run with a defined set of inputs
and returning one or several outputs. A <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> is a collection of
<strong>Nodes</strong> where data can flow in an logical manner, the output of one node serving as
input of another.</p>
<div class="section" id="simple-example">
<h2>Simple example<a class="headerlink" href="#simple-example" title="Permalink to this headline">¶</a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span>

<span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">f_my_function_2</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
    <span class="n">e</span> <span class="o">=</span> <span class="n">d</span> <span class="o">-</span> <span class="n">a</span>
    <span class="k">return</span> <span class="n">e</span>

<span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">f_my_function_1</span><span class="p">(</span><span class="n">c</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">c</span> <span class="o">/</span> <span class="mf">10.</span>

<span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">f_my_function_3</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
    <span class="k">return</span> <span class="n">c</span>

<span class="n">res</span> <span class="o">=</span> <span class="n">graph</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">})</span>
<span class="nb">print</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>pyungo</strong> is registering the functions at import time. It then resolve the DAG and figure out
the sequence at which the functions have to be run per their inputs / outputs. In this case,
it will be function 3 then 1 and finally 2.</p>
<p>The ordered <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> is run with calculate, with the given data. It returns
the output of the last function being run (<code class="docutils literal notranslate"><span class="pre">e</span></code>), but all intermediate results are also
available in the graph instance.</p>
<p>The result will be <cite>(a + b) / 10 - a = -1.5</cite></p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In the above example, most of the inputs / outputs are not explicitely defined when
registering. <strong>pyungo</strong> inspects the function signature to get the names and extract the
returned variable names automatically. For <code class="docutils literal notranslate"><span class="pre">f_my_function_1</span></code>, there is no returned
variable, so the output name needs to be explicitely provided.</p>
</div>
</div>
</div>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &copy;2019, Cedric Leroy.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 3.1.0</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
      |
      <a href="../_sources/source/gettingstarted.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    
    <a href="https://github.com/cedricleroy/pyungo" class="github">
        <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"  class="github"/>
    </a>
    

    
  </body>
</html>